package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: sky-take-out
 * @package: com.sky.controller.admin
 * @className: SetmealController
 * @author: Eric
 * @description: TODO
 * @date: 2023/9/22 17:40
 * @version: 1.0
 */
@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@RequiredArgsConstructor
public class SetmealController {
    private final SetmealService setmealService;

    /**
     * 页面
     *
     * @param setmealPageQueryDTO setmeal页面查询dto
     * @return {@link Result}
     */
    @GetMapping("/page")
    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO) {
        PageResult pageResult = setmealService.pag(setmealPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 创建套餐
     *
     * @param setmealDTO setmeal dto
     * @return {@link Result}
     */
    @PostMapping
    public Result<?> creatSetmeal(@RequestBody SetmealDTO setmealDTO) {
        setmealService.creatSetmeal(setmealDTO);
        return Result.success();
    }

    /**
     * 更改状态
     *
     * @param id     id
     * @param status 状态
     * @return {@link Result}
     */
    @PostMapping("/status/{status}")
    public Result<?> changeStatus(Long id, @PathVariable Integer status) {
        setmealService.changeStatus(id, status);
        return Result.success();
    }

    /**
     * 获取套餐
     *
     * @param id id
     * @return {@link Result}
     */
    @GetMapping("/{id}")
    public Result<SetmealVO> getSetmeal(@PathVariable Long id) {
        SetmealVO setmeal = setmealService.getSetmeal(id);
        return Result.success(setmeal);
    }

    /**
     * 按ids删除
     *
     * @param ids ids
     * @return {@link Result}<{@link ?}>
     */
    @DeleteMapping
    public Result<?> deleteByIds(String ids) {
        setmealService.deleteByIds(ids);
        return Result.success();
    }

    @PutMapping
    public Result<?> updateSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.updateSetmeal(setmealDTO);
        return Result.success();
    }
}
